<? 
	if(isset($_POST['btnsubmit']))
	{
		require("required/dbconnect.php");
		$id=$_POST['item'];
		$pid=$_POST['pid'];
		$quantity=$_POST['quantity'];
		
		$chk=mysql_query("select * from os_product_inventory where id=$id");
		
		if(mysql_result($chk,0,"quantity")<$quantity || $quantity==0){
			header("Location:os_view_full.php?id=$pid&error=1");	
		}
		else
		{
			$error=0;
			if(!empty($_SESSION['cart']))
			{
				  foreach($_SESSION['cart'] as $cartItems)
				  {
					  if($cartItems['id'] == $id)
					  {
							$error=1;
							break;
							  
					  }
				  }		
			}
			else
			{
				$error=0;
			}
			
				
			if($error==1){
			
				header("Location:os_mycart.php?id=$pid&error=3");
			}
			else
			{
			
				$_SESSION['cart'][] = array(
							   "quantity" => $quantity,
							   "id" => $id,
							   );

		
			header("Location:os_mycart.php?id=$pid&msg=1");
			
			}
		}
		
		
	  	
	}else{
	
		header("Location:os_invalid.php");
	}
?>	